﻿using Aweber.Entity;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Aweber;
using System.Configuration;

namespace IntegrationTests
{
    
    
    /// <summary>
    ///This is a test class for CampaignTest and is intended
    ///to contain all CampaignTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CampaignTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion
        
        /// <summary>
        ///A test for Campaign Constructor
        ///</summary>
        [TestMethod()]
        public void CampaignConstructorTest()
        {
            Adapter adapter = null;
            Campaign target = new Campaign(adapter);
            Assert.IsNotNull(target);
        }

        /// <summary>
        ///A test to see that all properties are loaded in the campaign
        ///</summary>
        [TestMethod()]
        public void CampaignPropertyTest()
        {
            string appId = ConfigurationManager.AppSettings["AweberAppId"];
            API api = new API(appId);
            api.process_appId_token(ConfigurationManager.AppSettings["AweberToken"]);

            Account target = api.getAccount();
                       
            Campaign campaign = target.lists().entries[3].campaigns().entries[0];

            Assert.IsNotNull(campaign, "You need a campaign in your account to test this properly");

            Assert.IsTrue(campaign.click_tracking_enabled == true);
            Assert.IsFalse(String.IsNullOrEmpty(campaign.content_type));
            Assert.IsFalse(String.IsNullOrEmpty(campaign.links_collection_link));
            Assert.IsFalse(String.IsNullOrEmpty(campaign.messages_collection_link));
            Assert.IsFalse(String.IsNullOrEmpty(campaign.spam_assassin_score));
            Assert.IsFalse(String.IsNullOrEmpty(campaign.subject));
            Assert.IsTrue(campaign.total_clicks >= 0);
            Assert.IsTrue(campaign.total_opens >= 0);
            Assert.IsTrue(campaign.total_sent >= 0);
            Assert.IsTrue(campaign.total_spam_complaints >= 0);
            Assert.IsTrue(campaign.total_clicks >= 0);
            Assert.IsTrue(campaign.total_undelivered >= 0);
            Assert.IsTrue(campaign.total_unsubscribes >= 0);

        }

    }
}
